#include<bits/stdc++.h>
using namespace std;
int n,q;
string a[1000005],b[1000005],q1[1000005],q2[1000005];
int main(){
	freopen("replace.in","r",stdin);
	freopen("replace.out","w",stdout);
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
	}
	for(int i=1;i<=q;i++){
		cin>>q1[i]>>q2[i];
		cout<<0<<'\n';
	}
	return 0;
} 
